package com.hn.vue.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hn.vue.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;

/**
 * hanni
 * 2019/3/8 0008
 * 10:04
 */

public class HnAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Autowired
    private ObjectMapper objectMapper;
    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {

        ResponseVo responseVo = new ResponseVo().ok("登录成功");
        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8.toString());
        httpServletResponse.getWriter().write(objectMapper.writeValueAsString(responseVo));

    }
}
